<template>
  <div class="qiaobi-wrap-container">
    <div class="qiaobi-box" @click="qiaobiClick">
      <div class="title">
        {{ type  }}
      </div>
      <div class="state">
        <span class="state-icon" :style="getIconBgColor(state)"></span>
        <span class="state-text" :style="getTextColor(state)">{{
          state | stateFilter
        }}</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "ItemWrap",
  props: {
    type: {
      type: String,
      default: "",
    },
    control: {
      type: String,
      default: "",
    },
    state: { type: [Number, String] }, // 健康 0 ，故障1 ，异常2
    id: { type: String, default: "0" },
  },
  filters: {
    stateFilter(val) {
      switch (val) {
        case "0":
          return "健康";
        case "2":
          return "故障";
        case "1":
          return "异常";
        case "3":
          return "正常";
        default:
          return "";
      }
    },
  },
  methods: {
    getIconBgColor(state) {
      return {
        "background-color":
          state == "0" || state == "3"
            ? "#1cbe21"
            : state == "2"
            ? "#ffaa00"
            : state == "1"
            ? "#ff3737"
            : "#1cbe21",
      };
    },
    getTextColor(state) {
      return {
        color:
          state == "0" || state == "3"
            ? "#1cbe21"
            : state == "2"
            ? "#ffaa00"
            : state == "1"
            ? "#ff3737"
            : "#1cbe21",
      };
    },
    qiaobiClick() {
      this.$emit("qiaobiClick", { type: this.type, control: this.control });
    },
  },
};
</script>
<style scoped lang="less">
.qiaobi-wrap-container {
  position: relative;
  width: 0;
  height: 0;
  padding: 10px;
  box-sizing: border-box;
  .qiaobi-box {
    cursor: pointer;
    width: 100%;
    height: 100%;
    padding-left: 10px;
    box-sizing: border-box;
    border: 1px solid #3099d1;
    background: rgba(48, 153, 209, 0.2);
    //margin: 8px;
  }
  .title {
    height: 50%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    font-size: 18px;
    color: #fff;
  }
  .state {
    height: 50%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    span.state-icon {
      display: inline-block;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      border: 1px solid #3099d1;
      margin-right: 5px;
      background: rgba(48, 153, 209, 0.2);
    }
    span.state-text {
      font-size: 14px;
    }
  }
}
</style>
